package redis

import (
	"Go_Advanced/bluebell/setting"
	"fmt"
	"github.com/go-redis/redis"
)

// 声明一个全局的rdb变量
var (
	client *redis.Client
	Nil = redis.Nil
)

func Init(cfg *setting.RedisConfig) (err error) {
	client= redis.NewClient(&redis.Options{
		Addr: fmt.Sprintf("%s:%d",
			cfg.Host,
			cfg.Port,
		),
		Password: cfg.Password, // no password set
		DB:       cfg.Db,       // use default DB
		PoolSize: cfg.PoolSize,
		MinIdleConns: cfg.MinIdleConns,
	})

	_, err = client.Ping().Result()
	return
}
func Close() {
	_ = client.Close()
}
